using UnityEngine;
/// <summary>
/// AbsHFSimulateBehaviour【IHFTime接口】
/// </summary>
public partial class AbsHFSimulateBehaviour : IHFTime
{
    #region IHFITime
    /// <summary>
    /// deltaTime
    /// </summary>
    public float deltaTime { get { return isIgnoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime; } }
    /// <summary>
    /// time
    /// </summary>
    public float time { get { return isIgnoreTimeScale ? Time.unscaledTime : Time.time; } }
    /// <summary>
    /// fixedDeltaTime
    /// </summary>
    public float fixedDeltaTime { get { return isIgnoreTimeScale ? Time.fixedUnscaledDeltaTime : Time.fixedDeltaTime; } }
    /// <summary>
    /// fixedTime
    /// </summary>
    public float fixedTime { get { return isIgnoreTimeScale ? Time.fixedUnscaledTime : Time.fixedTime; } }    
    /// <summary>
    /// 是否忽略时间缩放
    /// </summary>
    public bool isIgnoreTimeScale { get; private set; }
    /// <summary>
    /// 切换时间缩放
    /// </summary>
    /// <param name="_isIgnoreTimeScale">是否忽略时间缩放</param>
    public void ToggleTimeScale(bool _isIgnoreTimeScale)
    {
        bool before = isIgnoreTimeScale;
        OnBeforeToggleTimeScale(this, before, _isIgnoreTimeScale);        
        isIgnoreTimeScale = _isIgnoreTimeScale;
        OnToggleTimeScale(this, before, _isIgnoreTimeScale);
        OnAfterToggleTimeScale(this, before, _isIgnoreTimeScale);
    }
    /// <summary>
    /// 切换TimeScale之前
    /// <param name="_self">缩放时间对象</param>
    /// <param name="_beforeIsIgnoreTimeScale">修改前是否忽略时间缩放</param>
    /// <param name="_afterIsIgnoreTimeScale">修改后是否忽略时间缩放</param>
    protected virtual void OnBeforeToggleTimeScale(IHFTime _self, bool _beforeIsIgnoreTimeScale, bool _afterIsIgnoreTimeScale) { }
    /// <summary>
    /// 切换时间缩放
    /// </summary>
    /// <param name="_time">时间</param>
    /// <param name="_beforeIsIgnoreTimeScale">修改前是否忽略时间缩放</param>
    /// <param name="_afterIsIgnoreTimeScale">修改后是否忽略时间缩放</param>
    protected virtual void OnToggleTimeScale(IHFTime _time, bool _beforeIsIgnoreTimeScale, bool _afterIsIgnoreTimeScale) { }
    /// <summary>
    /// 切换TimeScale之后
    /// </summary>
    /// <param name="_self">缩放时间对象</param>
    /// <param name="_beforeIsIgnoreTimeScale">修改前是否忽略时间缩放</param>
    /// <param name="_afterIsIgnoreTimeScale">修改后是否忽略时间缩放</param>
    protected virtual void OnAfterToggleTimeScale(IHFTime _self, bool _beforeIsIgnoreTimeScale, bool _afterIsIgnoreTimeScale) { }

    /// <summary>
    /// 同步时间缩放
    /// </summary>
    /// <param name="_syncTime">同步时间</param>
    public void SyncTimeScale(IHFTime _syncTime)
    {
        OnBeforeSyncTimeScale(_syncTime);
        OnSyncTimeScale(_syncTime);
        OnAfterSyncTimeScale(_syncTime);
    }
    /// <summary>
    /// 同步TimeScale之前
    /// </summary>
    /// <param name="_self">同步对象</param>
    protected virtual void OnBeforeSyncTimeScale(IHFTime _self) { }    
    /// <summary>
    /// 同步时间缩放
    /// </summary>
    /// <param name="_syncTime">同步时间</param>
    protected virtual void OnSyncTimeScale(IHFTime _syncTime) { }
    /// <summary>
    /// 同步TimeScale之后
    /// </summary>
    /// <param name="_self">同步对象</param>
    protected virtual void OnAfterSyncTimeScale(IHFTime _self) { }
    #endregion
}
